The Map
object holds key-value pairs and remembers the original insertion order of the keys. Whereas, the WeakMap
object is a collection of key/value pairs in which the keys are weakly referenced. You can use any data type as a key or value in a Map
whereas in WeakMap
you can only use objects as keys. The WeakMap
is not iterable whereas Map
is. In WeakMap
it holds the weak reference to the original object which means if there are no other references to an object stored in the WeakMap
, those objects can be garbage collected.